﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhongMachTu.OConnection;
using PhongMachTu.OModel;

namespace PhongMachTu.OForm
{
    public partial class FormChangePassword : Form
    {
        public FormChangePassword()
        {
            InitializeComponent();
        }

        private void FormChangePassword_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            FormManager.mainForm.Show();
            FormManager.changePwdForm.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (OSession.isLoggedIn())
            {
                string pwd = textBox1.Text;
                int userid = OSession.LoggedInUser.Id;
                if (DataManipulate.updatePassword(userid, pwd))
                {
                    MessageBox.Show("Thay đổi thành công");
                }
                else
                {
                    MessageBox.Show("Thay đổi thất bại");
                }
            }
            else
            {
                FormManager.loginForm.Show();
                FormManager.changePwdForm.Hide();
            }
            
        }
    }
}
